package user

import (
	"cgs-server/helper"
	"cgs-server/server"
	"cgs-server/server/system"
	"net/http"
)

func init() {
	//server.Handle(http.MethodGet, "/api/User/Info", GetUserInfo, server.Login)
}

// List returns the user list.
func GetUserInfo2(w http.ResponseWriter, r *http.Request) {
	user, err := server.GetCurrentUser(r)

	if err != nil {
		_, _ = helper.WriteJSON(w, server.Fail(err.Error()))
		return
	}

	// 获取所有权限
	authorities := server.GetAllAuthorities()
	authorityMap := map[string]bool{}
	for _, i := range authorities {
		enabled := false
		for _, id := range user.OperatingAuthorities {
			if id == i.ID {
				enabled = true
				break
			}
		}

		authorityMap[i.ID] = enabled
	}

	_, _ = helper.WriteJSON(w, server.CgsResult{
		Code: 200,
		Msg:  "Get successfully!",
		Data: system.UserInfo{
			User: *user,
			Authority: authorityMap,
		},
	})
}
